<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.thymeleaf.org"
      layout:decorator="fragments/layout">
<head>
    <title>分类/标签管理</title>
    <style>
        .dropDown_A{
            color: #fff;
        }
        .dropDown_A:hover{
            color: #ffffff;
        }

    </style>
</head>
<body>
<!--这个模板是继承模板只能替换内容。并且只能在head部分添加自己的js css.
    body中不能写任何的数据，如果body中的模块不是 继承模板中的内容都会被替换掉。
-->

<section class="Hui-article-box" layout:fragment="content">
    <!--导航条提示-->
    <nav class="breadcrumb"><i class="Hui-iconfont"></i> <a href="/" class="maincolor">首页</a> <span class="c-999 en">&gt;</span><span class="c-666">分类/标签管理</span> <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <!--导航条提示-->
    <!--页面主体-->
    <div class="Hui-article">
        <article class="cl pd-20">

            <div class="mt-10">
                <div class="row cl">
                    <div class="col-md-7">
                        <div class="panel panel-default">
                            <div class="panel-header">分类列表</div>
                            <div class="panel-body">
                                <button type="button" th:each="c : ${categories}" style="margin-top: 3px;" class="dropDown dropDown_hover btn" th:attrappend="class=${' ' + colors[c.id%6]}">
                                    <a class="dropDown_A" href="#" th:text="${c.get('name')}+'('+${c.get('count')}+')'">默认分类</a>
                                    <ul class="dropDown-menu menu radius box-shadow" th:if="${c.get('id')} ne 1">
                                        <li><a href="#" th:onclick="'admin_edit(\''+${c.get('id')}+'\')'">修改</a></li>
                                        <li><a href="#" th:onclick="'admin_del_c(\''+${c.get('id')}+'\')'">删除</a></li>
                                    </ul>
                                </button>

                            </div>
                        </div>

                    </div>
                    <div class="col-md-5">
                        <div class="panel panel-default">
                            <div class="panel-header">标签列表</div>
                            <div class="panel-body">
                                <button type="button" th:each="t : ${tags}" style="margin-top: 3px;" class="dropDown dropDown_hover btn" th:attrappend="class=${' ' + colors[t.id%6]}">
                                    <a class="dropDown_A" href="#" th:text="${t.get('name')}+'('+${t.get('count')}+')'">默认分类</a>
                                    <ul class="dropDown-menu menu radius box-shadow">
                                        <li><a href="#" th:onclick="'admin_del_t(\''+${t.get('id')}+'\')'">删除</a></li>
                                    </ul>
                                </button>
                            </div>
                        </div>

                    </div>

                </div>
            </div>

            <div class="mt-10">
                <div class="row">
                <div class="col-xs-5">
                    <div class="panel panel-default">
                        <div class="panel-header">分类管理</div>
                        <div class="panel-body">

                            <input type="hidden" id="mid"  />
                            <input type="hidden" id="mtype"  value="category"/>
                            <input type="text" id="category_name" class="input-text" placeholder="请输入分类名称"/>

                            <button type="button" id="saveCategory" class="mt-10 btn btn-success">保存分类</button>
                        </div>
                    </div>
                </div>
                </div>
            </div>

        </article>
    </div>
    <!--页面主体-->
</section>

<div layout:fragment="footerjs">
    <script th:inline="javascript">
        /*<![CDATA[*/

        $("#saveCategory").on('click',function () {
            var name = $("#category_name").val();
            if(!name){
                layer.alert("请输入分类名称");
                return false;
            }
            $.post(basepath+"/metas/save",{id:$("#mid").val(),name:name,type:$("#mtype").val()},function(data){
                if(data == 1){
                    location.href=basepath+"/metas/index";
                }
            });
        });

        /*管理员-用户-编辑*/
        function admin_edit(id){
            $("#mid").val(id);
            $.get(basepath+"/metas/edit/"+id,{t:new Date().getTime()},function(data){
                console.info(data.data);
                var metas = data.data;
                $("#category_name").val(metas.name);
                $("#mtype").val(metas.type);
            });
        }
        /*管理员-用户-删除*/
        function admin_del_c(id){
            layer.confirm('删除须谨慎，确认要删除吗？',function(index){
                //此处请求后台程序，下方是成功后的前台处理……

                $.get(basepath+"/article/delete/"+id,{ts:new Date().getTime()},function(data){
                    if(data==1){
                        location.replace(location.href);
                    }
                });
            });
        }

        function admin_del_t(id){
            layer.confirm('删除须谨慎，确认要删除吗？',function(index){
                //此处请求后台程序，下方是成功后的前台处理……

                $.get(basepath+"/metas/delete_t/"+id,{ts:new Date().getTime()},function(data){
                    if(data == 1){
                       location.href =basepath+"/metas/index";
                    }
                });
            });
        }


        /*]]>*/
    </script>
</div>


</body>
</html>